package com.yylending.las.lending.increase;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yylending.las.Global;
import com.yylending.las.common.AESEntity;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by Pengrf on 2017/6/20.
 * Copyright  2017 www.yyfax.com. All Rights Reserved.
 */
public class IncreaseModel extends Model {
	private static final String TAG = "IncreaseModel";
	public static final int METHOD_INCREASE_BY_POLICY = 0;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		switch (functionalCode) {
			case METHOD_INCREASE_BY_POLICY:
				return service.promoteLoan(Global.LOGIN_TOKEN, (AESEntity) params);
		}
		return null;
	}

	@Override
	public void onNext(Object entity) {
		CLog.i(TAG, "onNext: " + entity.toString());
		BaseResultEntity result = cast(entity);
		switch (result.requestCode) {
			case METHOD_INCREASE_BY_POLICY:
				IncreaseResult increaseResult = cast(entity);
				EventAgent.post(increaseResult);
				break;

		}
	}

	private interface Service {
		@POST("server/loan/promoteLoan")
		Observable<IncreaseResult> promoteLoan(@Header("token") String token, @Body AESEntity params);
	}

	public static class IncreaseParams {
		/**
		 * name :用户名
		 * pass :密码
		 * assort :保单1 ;公积金2 ;社保3
		 * type :平安寿险101
		 */

		public String name;
		public String pass;
		public String assort;
		public String type;

		public IncreaseParams(){}

		public IncreaseParams(String name, String pass, String assort, String type) {
			this.name = name;
			this.pass = pass;
			this.assort = assort;
			this.type = type;
		}
	}

	static class IncreaseResult extends BaseResultEntity {
	}

	/**
	 * 提额参数Bean类
	 */
	public static class PromoteInfo {

	}
}
